package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.ldc.common.model.BasePagingModel;
import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.wandroid.model.SquareArticleModel;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.server.ApiServer;

import java.util.List;

public class SquareViewModel extends ViewModelBase {
    private final ApiServer apiServer = Api2Request.getInstance().createServer(ApiServer.class);

    private final MutableLiveData<BasePagingModel<SquareArticleModel>> _squareArticleList = new MutableLiveData<>();


    public LiveData<BasePagingModel<SquareArticleModel>> getSquareArticleList() {
        return _squareArticleList;
    }


    public void getSquareArticle(int page) {
        apiRequest(apiServer.get_user_article(page), (ok, result, throwable) -> {
            if (result.isSuccess()) {
                _squareArticleList.setValue(result.getData());
            } else {
                _squareArticleList.setValue(null);
            }
        });
    }
}
